package com.exercises;


import com.exercises.common.ListNode;

public class Exercise160 {
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        //0,9,1,2,4  ->0,9,1,2,4,3,2,4
        //3,2,4      ->3,2,4,0,9,1,2,4
        if (headA == null || headB == null) {
            return null;
        }
        ListNode pA = headA, pB = headB;
        while (pA != pB) {
            System.out.println(pA.val);
            System.out.println(pB.val);
            System.out.println("========");
            pA = pA == null ? headB : pA.next;
            pB = pB == null ? headA : pB.next;
        }
        return pA;
    }
}